package com.immi.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.DB.DBHelper;

/**
 * Servlet implementation class emOthersAdd
 */
@WebServlet("/emOthersAdd")
public class emOthersAdd extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public emOthersAdd() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 response.setContentType("text/html;charset=UTF-8");
		 response.setCharacterEncoding("UTF-8");
		 String answer=new String(request.getParameter("newAnswer").getBytes("ISO-8859-1"),"UTF-8");
		 int score=0;
		 if(!request.getParameter("addscore").equals("分数"))
		 {
			 String scoretemp=request.getParameter("addscore");
			 score=new Integer(request.getParameter("addscore"));
		 }
		 DBHelper.insertNewQuestIntoDB(answer, score);
		 
		 RequestDispatcher dispatcher=request.getRequestDispatcher("/evaluationManage.jsp");
		 dispatcher.forward(request, response);
		 
	}

}
